# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-06-21
# @File : 7_register_v2_version.py

import requests
import uuid

import hashlib


def sha1(data_string):
    # sha1加密
    hash_object = hashlib.sha1()
    hash_object.update(data_string.encode('utf-8'))
    arg7 = hash_object.hexdigest()
    return arg7


device_token = str(uuid.uuid4())
# device_token = "6f0215a1-46cc-472c-a4e8-5a62e2f1e036"
param_dict = {
    "app_name": "achievo_ad",
    "app_version": "7.83.3",
    "device_token": device_token,
    "status": "1",
    "warehouse": "null",
    "manufacturer": "Google",
    "device": "Pixel+2+XL",
    "os_version": "29",
    "channel": "oziq7dxw%3A%3A%3A",
    "vipruid": "",
    "regPlat": "0",
    "regid": "null",
    "rom": "Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+10%3B+M2007J17C+MIUI%2FV12.0.11.0.QJSCNXM%29",
    "skey": "6692c461c3810ab150c9a980d0c275ec"
}

ordered_string = "&".join(["{}={}".format(key, param_dict[key]) for key in sorted(param_dict.keys())])
# 还未排序 app_name=achievo_ad&app_version=7.83.3&channel=oziq7dxw%3A%3A%3A&device=Pixel+2+XL&device_token=50656e23-cd90-4aa3-925a-f64cd1377b6a&manufacturer=Google&os_version=29&regPlat=0&regid=null&rom=Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+10%3B+M2007J17C+MIUI%2FV12.0.11.0.QJSCNXM%29&skey=6692c461c3810ab150c9a980d0c275ec&status=1&vipruid=&warehouse=null
# 排序后的 app_name=achievo_ad&app_version=7.83.3&device_token=cef3f807-c9fc-3ceb-a818-74ad1ecd48aa&status=1&warehouse=VIP_NH&manufacturer=Google&device=Pixel+2+XL&os_version=29&channel=oziq7dxw%3A%3A%3A&vipruid=&regPlat=0&regid=null&rom=Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+10%3B+Pixel+2+XL+Build%2FQQ3A.200805.001%29&skey=6692c461c3810ab150c9a980d0c275ec
# print(ordered_string)

salt = "aee4c425dbb2288b80c71347cc37d04b"
tmp = sha1(f"{salt}{ordered_string}")   #  ordered_string进行排序
api_sign = sha1(f"{salt}{tmp}")

res = requests.get(
    url="https://mp.appvipshop.com/apns/device_reg",
    params=param_dict,
    headers={
        "Authorization": "OAuth api_sign={}".format(api_sign)
    }
)
print(res.text)